package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：daqiang
 * @date ：Created in 2019/11/25
 * @description ：
 * @version: 1.0
 */

@RestController
@RequestMapping("/member")
public class MemberController {

    @Reference
    MemberService memberService;

    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Member member = memberService.findById(id);
            return new Result(true, null,member);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, null);
        }
    }

    @RequestMapping("/submit")
    public Result submit(@RequestBody Member member){
        try {
            memberService.edit(member);
            return new Result(true,MessageConst.EDIT_MEMBER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConst.EDIT_MEMBER_FAIL);
        }
    }
}
